﻿// Copyright (c) 2014 Morten Bakkedal
// This code is published under the MIT License.

using System;
using FuncLib.Functions;
using FuncLib;
using FuncLib.Mathematics;

namespace FuncLibSamples.Testing.ComplexFunctions
{
	public class ComplexVariable : ComplexFunction
	{
		private ComplexInnerVariable re, im;

		public ComplexVariable()
		{
			re = new ComplexInnerVariable(this);
			im = new ComplexInnerVariable(this);
		}

		protected override Complex ComputeValue(IEvaluator evaluator)
		{
			return new Complex(re.Value(evaluator), im.Value(evaluator));
		}

		protected override ComplexFunction ComputeDerivative(ComplexVariable variable)
		{
			return variable == this ? 1.0 : 0.0;
		}

		protected override Function Re()
		{
			return re;
		}

		protected override Function Im()
		{
			return im;
		}

		public static ComplexVariableAssignment operator |(ComplexVariable variable, Complex value)
		{
			return new ComplexVariableAssignment();
		}

		public Variable InnerReVariable
		{
			get
			{
				return re;
			}
		}

		public Variable InnerImVariable
		{
			get
			{
				return im;
			}
		}
	}
}
